﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cronos.DateTimeExtensions
{
    public struct TimePeriod
    {
        private DateTime _start;
        public DateTime Start
        {
            get { return _start; }
        }


        private DateTime _end;
        public DateTime End
        {
            get { return _end; }
        }

        public TimePeriod(DateTime start, DateTime end)
        {
            if (!(end > start)) throw new ArgumentOutOfRangeException();

            _start = start;
            _end = end;
        }

        public static TimePeriod TodayFullDay()
        {
            return CreatePeriodFor(DateTime.Today);
        }

        public static TimePeriod CurrentWeek()
        {
            return new TimePeriod
            {
                _start = DateTime.Today.FirstDayOfWeek().BeginningOfDay(),
                _end = DateTime.Today.LastDayOfWeek().EndingOfDay()
            };
        }

        public static TimePeriod CurrentWorkWeek()
        {
            return new TimePeriod
            {
                _start = DateTime.Today.FirstWorkDayOfWeek().BeginningOfDay(),
                _end = DateTime.Today.LastWorkDayOfWeek().EndingOfDay()
            };
        }

        public static TimePeriod CurrentMonth()
        {
            return new TimePeriod
            {
                _start = DateTime.Today.FirstDayOfMonth().BeginningOfDay(),
                _end = DateTime.Today.LastDayOfMonth().EndingOfDay()
            };
        }

        public static TimePeriod CreatePeriodFor(DateTime date)
        {
            return new TimePeriod { _start = date.BeginningOfDay(), _end = date.EndingOfDay() };
        }

        public override string ToString()
        {
            return String.Format("{0} to {1}", _start.ToString(), _end.ToString());
        }
    }
}